//201902104003邵潇漩
package bysj.service;

import bysj.dao.OpenAreaDao;
import bysj.domain.OpenArea;
import bysj.exception.BysjException;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public class OpenAreaService {
    private static OpenAreaDao openAreaDao= OpenAreaDao.getInstance();
    private static OpenAreaService openAreaService=new OpenAreaService();
    private OpenAreaService(){}
    public static OpenAreaService getInstance(){
        return openAreaService;
    }
    public Collection<OpenArea> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException {
        //获得连接以便完成可能的事务操作
        Connection connection = JdbcHelper.getConn();
        Collection<OpenArea> openAreas = openAreaDao.findAll(connection,conditionList,pagination);
        JdbcHelper.close(connection);
        return openAreas;
    }
    public OpenArea find(Integer id) throws SQLException {
        //获得连接以便完成可能的事务操作
        Connection connection = JdbcHelper.getConn();
        OpenArea openArea=openAreaDao.find(connection,id);
        JdbcHelper.close(connection);
        return openArea;
    }
    public boolean update(OpenArea openArea) throws SQLException {
        //获得连接以便完成可能的事务操作
        Connection connection = JdbcHelper.getConn();
        boolean openArea_update=openAreaDao.update(connection,openArea);
        JdbcHelper.close(connection);
        return openArea_update;
    }
    public boolean add(OpenArea openArea) throws SQLException {
        //获得连接以便完成可能的事务操作
        Connection connection = JdbcHelper.getConn();
        boolean openArea_add=OpenAreaDao.getInstance().add(connection,openArea);
        JdbcHelper.close(connection);
        return openArea_add;
    }
    public boolean delete(Integer id) throws SQLException, BysjException {
        OpenArea openArea=this.find(id);
        return this.delete(openArea);
    }

    public boolean delete(OpenArea openArea) throws SQLException,BysjException {
        //获得连接
        Connection connection = JdbcHelper.getConn();
        boolean openArea_del=openAreaDao.delete(connection,openArea);
        JdbcHelper.close(connection);
        return openArea_del;

    }
}
